﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;


namespace HRdex_Final
{
    public partial class HRMainMaster : System.Web.UI.MasterPage
    {
        DataTable dtbl = new DataTable("dt");
        SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\HRdexDB.mdf;Integrated Security=True;User Instance=True");

        string SessionID()
        {
           return Session["EmployeeID"].ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("SELECT formEmployees.EmployeeID, formEmployees.Password, catUserLevel.catUserLevelName FROM formEmployees INNER JOIN  catUserLevel ON formEmployees.UserLevelID = catUserLevel.UserLevelID WHERE (formEmployees.EmployeeID = " + SessionID() + ")", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dtbl);

            if (dtbl.Rows[0].ItemArray[2].ToString() == "Admin" || dtbl.Rows[0].ItemArray[2].ToString() == "SubAdmin" || dtbl.Rows[0].ItemArray[2].ToString() == "Staff")
            {
                AdminNavigation.Visible = true;
                EmpNavigation.Visible = false;
            }
            else
            {
                EmpNavigation.Visible = true;
                AdminNavigation.Visible = false;
            }

            AdminNavigation.Items[2].Text = "Message(" + msgnotif(SessionID()) + ")";
            EmpNavigation.Items[1].Text = "Message(" + msgnotif(SessionID()) + ")";

            //if (dtbl.Rows[0].ItemArray[2].ToString() == "Faculty")
            //{
            //    EmpNavigation.Items[4].ChildItems.RemoveAt(1);
            //}
            //if (dtbl.Rows[0].ItemArray[2].ToString() == "Employee")
            //{
            //    EmpNavigation.Items[4].ChildItems.RemoveAt(3);
            //}

            
        }
        string msgnotif(string empid)
        {
            string scmd = "SELECT COUNT(Readed) AS unread FROM  formMessegeSender WHERE  (fromEmpID = " + empid + ") AND (Readed <> 1)";
            SqlDataAdapter cmd = new SqlDataAdapter(scmd, conn);

            DataTable dtbl = new DataTable();

            cmd.Fill(dtbl);

            

            return dtbl.Rows[0][0].ToString();
        }

    }
}